import { defineStore } from 'pinia'

//counter:需要唯一
export const useCounterStore = defineStore('counter', {
    state: () => ({ count: 0,userName:'张三',password:'12312' }), //state 定义数据 这里相当于定义了全局变量
    getters: { //类似于计算属性:里面的值如果变化 会触发重新计算
        double: (state) => state.count * 2,//double:结果变量
        userInfo:(state)=>state.userName + '|' +state.password
    },
    actions: { //可以定义方法 操作state中的数据
        increment() {
            this.count++
        },
        changeUserInfo(userName,password){
            this.userName = userName
            this.password = password
        }
    },
    // 开启数据缓存
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'userInfo',//设置存储的key
                storage: localStorage,//表示存储在localStorage
            }
        ]
    }
})

